<template>
  <div>
    测试
    <el-button @click="but">{{ str }}</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [1, 2, 3],
      str: 0,
    };
  },
  created() {
    this.str = this.arr.shift();
  },
  methods: {
    but: function() {},
  },
  mounted() {
    function Queue() {
      //初始化队列（使用数组实现）
      var items = [];

      //向队列（尾部）中插入元素
      this.enqueue = function(element) {
        items.push(element);
      };

      //从队列（头部）中弹出一个元素，并返回该元素
      this.dequeue = function() {
        return items.shift();
      };

      //查看队列最前面的元素（数组中索引为0的元素）
      this.front = function() {
        return items[0];
      };

      //查看队列是否为空，如果为空，返回true；否则返回false
      this.isEmpty = function() {
        return items.length == 0;
      };

      //查看队列的长度
      this.size = function() {
        return items.length;
      };

      //查看队列
      this.print = function() {
        //以字符串形势返回
        return items.toString();
      };
    }

    var queue = new Queue();
    queue.enqueue("hello");
    queue.enqueue("world");
    queue.enqueue("php");
    queue.enqueue("javascript");
    queue.enqueue("node.js");
    console.log(queue.isEmpty()); // false
    console.log(queue.print()); //hello,world,php,javascript,node.js
    console.log(queue.size()); //5
    console.log(queue.front()); //hello

    console.log(queue.dequeue()); //hello
    console.log(queue.isEmpty()); //false
    console.log(queue.print()); //world,php,javascript,node.js
    console.log(queue.size()); //4
    console.log(queue.front()); //world

    console.log(queue.dequeue()); //world
    console.log(queue.dequeue()); //php
    console.log(queue.dequeue()); //javascript
    console.log(queue.dequeue()); //node.js
    console.log(queue.isEmpty()); //true
    console.log(queue.print()); //(空字符串)
    console.log(queue.size()); //0
    console.log(queue.front()); // undefined
  },
};
</script>

<style></style>
